package cn.stylefeng.guns.modular.launchpad.controller;

import cn.stylefeng.guns.modular.base.util.Result;
import cn.stylefeng.guns.modular.launchpad.entity.Pledge;
import cn.stylefeng.guns.modular.launchpad.entity.Product;
import cn.stylefeng.guns.modular.launchpad.service.PledgeService;
import cn.stylefeng.guns.modular.launchpad.service.ProductService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@ApiOperation("App质押赎回控制器")
@RestController
@RequestMapping("/api/product")
public class AppProductController {

    @Autowired
    private PledgeService pledgeService;

    @Autowired
    private ProductService productService;


    // 获取产品列表
    @GetMapping("/getProductList")
    public Result getProductList(Product product) {
        return Result.success(productService.getListForApp(product));
    }

    // 质押
    @PostMapping("/impawn")
    public Result impawn(Pledge pledge, @RequestHeader("token") String token) {
        pledgeService.impawn(pledge, token);
        return Result.success();
    }

    // 查询个人某奖池质押数量
    @GetMapping("/getPledgeAmount")
    public Result getPledgeAmount(@RequestParam("productId") Long productId, @RequestParam("pledgeCoin") String pledgeCoin, @RequestHeader("token") String token) {
        return Result.success(pledgeService.getPledgeAmount(productId, pledgeCoin, token));
    }


    // 赎回
    @PostMapping("/redeem")
    public Result redeem(Pledge pledge, @RequestHeader("token") String token) {
        pledgeService.redeem(pledge, token);
        return Result.success();
    }

    // 查询分发记录
    @GetMapping("/getDistributionList")
    public Result getDistributionList(@RequestHeader("token") String token) {
        return Result.success(pledgeService.getDistributionList(token));
    }

    // 查询个人待领取奖励
    @GetMapping("/getPendingReward")
    public Result getPendingReward(@RequestHeader("token") String token) {
        return Result.success(pledgeService.getPendingReward(token));
    }

    // 领取个人奖励
    @PostMapping("/receiveReward")
    public Result receiveReward(@RequestHeader("token") String token) {
        pledgeService.receiveReward(token);
        return Result.success();
    }

    // 查询领取记录
    @GetMapping("/getReceiveList")
    public Result getReceiveList(@RequestHeader("token") String token) {
        return Result.success(pledgeService.getReceiveList(token));
    }


}
